<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.*" %>
<%@page import="com.mysql.jdbc.*" %>
<%@page import="java.lang.*" %>
<!DOCTYPE html>
<%
    response.setCharacterEncoding("utf-8");
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8 " />
        <script charset="utf-8" src="/zjcwkj/admin/editor/kindeditor-min.js"></script>
        <script charset="utf-8" src="/zjcwkj/admin/editor/lang/zh_CN.js"></script>
        <link href="/zjcwkj/css/mycss.css" rel=stylesheet></link>
        <script>
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create('textarea[name="content"]', {
                    resizeType : 1,
                    allowPreviewEmoticons : false,
                    allowImageUpload : false,
                    items : [
                        'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                        'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                        'insertunorderedlist', '|', 'emoticons', 'image', 'link']
                });
            });
        </script>
    </head>
    <body style="background-color: #FFFFFF;">
        <div align="center">
            <%

                String driverName = "com.mysql.jdbc.Driver";
                String userName = "root";
                String userPasswd = "1";
                String dbName = "zjcwkj";
                String dbTable;
                String SQL;
                String url = "jdbc:mysql://localhost/" + dbName + "?user=" + userName + "&password=" + userPasswd;
                Class.forName("com.mysql.jdbc.Driver");
                java.sql.Connection connection = DriverManager.getConnection(url);
                java.sql.Statement statement = connection.createStatement();
                ResultSet rs;
                String idString = request.getParameter("id");
                if (idString == null) {
                    idString = "1";
                }
                int id = Integer.parseInt(idString);
                switch (id) {
                    case 1:
                        dbTable = "info";
                        SQL = "select home from " + dbTable;
                        rs = statement.executeQuery(SQL);
                        if (rs.next()) {
                            out.print(rs.getString(1));
                        }
                        break;


                    case 2:
                        dbTable = "info";
                        SQL = "select info from " + dbTable;
                        rs = statement.executeQuery(SQL);
                        if (rs.next()) {
                            out.print(rs.getString(1));
                        }
                        break;
                    case 3:
                        dbTable = "info";
                        SQL = "select teacher from " + dbTable;
                        rs = statement.executeQuery(SQL);

                        if (rs.next()) {
                            out.print(rs.getString(1));
                        }
                        break;
                    case 4:
            %>
            <h3>教学大纲</h3>
            <%
                dbTable = "syllabus";
                SQL = "select name,filename from " + dbTable;
                rs = statement.executeQuery(SQL);

                while (rs.next()) {
            %>
            <li>
                <a href="<%=rs.getString("filename")%>"> <%= rs.getString("name")%> </a>
            </li>
            <%
                    }
                    while (rs.next()) {
                    }
                    break;
                case 5:
                    dbTable = "courseware";
                    SQL = "select name,coursewarename,planname from " + dbTable;
                    rs = statement.executeQuery(SQL);

            %>
            <table style="BORDER-RIGHT: #808080 1px groove; BORDER-TOP: #808080 1px groove; BORDER-LEFT: #808080 1px groove; BORDER-BOTTOM: #808080 1px groove" cellSpacing=0 cellPadding=0 width="100%" align=center border=1>
                <tr>
                    <td>
                        <b>目录</b>
                    </td>
                    <td><b>课件</b>
                    </td>
                    <td><b>教案</b>
                    </td>
                </tr>

                <%
                        while (rs.next()) {
                            out.print("<tr>");
                            out.print("<td>");
                            out.print(rs.getString("name"));
                            out.print("</td>");
                            out.print("<td>");
                            out.print("<a href=\"" + rs.getString("coursewarename") + "\"><img width=\"16px\" height=\"16px\" alt=\"ppt\" src=\"images/icon_ppt.gif\"></a>");
                            out.print("</td>");
                            out.print("<td>");
                            out.print("<a href=\"" + rs.getString("coursewarename") + "\"><img width=\"16px\" height=\"16px\" alt=\"ppt\" src=\"images/icon_pdf.gif\"></a>");
                            out.print("</td>");
                            out.print("</tr>");
                        }
                        out.print("</table>");
                        break;
                    case 6:
                        dbTable = "video";
                        SQL = "select * from " + dbTable;
                        rs = statement.executeQuery(SQL);
                %>


                <table cellspacing="0" rules="all" border="1" style="width:100%;border-collapse:collapse;font-size:13px;">
                    <th scope="col">序号</th><th scope="col">课程名称</th><th align="center" valign="middle" scope="col">主讲人</th><th align="center" valign="middle" scope="col">操作</th>

                    <%
                        int nI = 1;
                        while (rs.next()) {
                    %>
                    <tr>
                        <td>
                            <%= nI%>
                        </td>
                        <td>
                            <%= rs.getString("name")%>
                        </td>
                        <td>
                            <%=rs.getString("speakername")%>
                        </td>
                        <td>
                            <a href=" <%=rs.getString("videolocation")%>">下载</a>
                        </td>
                    </tr>
                    <% nI++;
                        }%>
                </table>
                <%

                        break;

                    case 7:
                        dbTable = "exercise";
                        SQL = "select * from " + dbTable;
                        rs = statement.executeQuery(SQL);
                        out.print("<h3>习题与样题</h3>");
                        while (rs.next()) {
                            out.print("<li><a href=\"" + rs.getString("exerciselocation") + "\">" + rs.getString("name") + "</a></li>");
                        }
                        break;
                    case 8:
                        dbTable = "practice";
                        SQL = "select * from " + dbTable;
                        rs = statement.executeQuery(SQL);
                        out.print("<h3>课程实验与实践</h3>");
                        while (rs.next()) {
                            out.print("<li><a href=\"" + rs.getString("practicelocation") + "\">" + rs.getString("name") + "</a></li>");
                        }
                        break;
                    case 9:
                        dbTable = "info";
                        SQL = "select material from " + dbTable;
                        rs = statement.executeQuery(SQL);
                        out.print("<h3>参考资料</h3>");
                        if (rs.next()) {
                            out.print(rs.getString("material"));
                        }
                        break;
                    case 10:
                        dbTable = "qa";
                        SQL = "select * from " + dbTable + " where flag=1";
                        rs = statement.executeQuery(SQL);
                  
                        while (rs.next()) {
                %>
                <div class="div_q">
                    <p class="p_q">问题：<%=rs.getString("question")%></p>
                </div>
                <div class="div_a">
                    <p class="p_a">回答：<%=rs.getString("anwser")%></p>
                </div>
                <%}
                %>
                <div>
                    <form action="admin/WriteDB?case=10&action=add" method="POST">
                        <textarea name="content" style="width:500px;height:200px;visibility:hidden;">请留言</textarea>
                        <input type="submit" value="提交" />
                    </form>
                </div>
                <%
                            break;
                        default:
                            break;
                    }

                    connection.close();

                %>
        </div>
    </body>
</html>
